package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.DeliveryManagementDetail;
import com.intelligent.service.DeliveryManagementDetailService;
import com.intelligent.utils.Result;
import com.intelligent.vo.DeliveryDetailPageReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/delivery-detail")
public class DeliveryManagementDetailController {

    @Autowired
    private DeliveryManagementDetailService detailService;

    @PostMapping("/page")
    public Result<Page<DeliveryManagementDetail>> page(@RequestBody DeliveryDetailPageReq req) {
        Page<DeliveryManagementDetail> page = detailService.page(req);
        return Result.success(page);
    }

    @PostMapping
    public Result<DeliveryManagementDetail> create(@RequestBody DeliveryManagementDetail detail) {
        try {
            DeliveryManagementDetail created = detailService.create(detail);
            return Result.success(created);
        } catch (Exception e) {
            return Result.error("创建失败：" + e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Result<DeliveryManagementDetail> detail(@PathVariable Long id) {
        DeliveryManagementDetail d = detailService.detail(id);
        return d == null ? Result.error("未找到数据") : Result.success(d);
    }
}


